package com.stockz.equity.manager;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.equity.dao.BarDao;
import com.stockz.equity.model.Bar;

@Component
public class BarManagerImpl implements BarManager {

	@Autowired private ScripManager scripManager;
	@Autowired private BarDao barDao;
	
	@Override
	public void persist(Bar bar) {
		barDao.persist(bar);
	}
	
	@Override
	public void persistAll(Collection<Bar> barList) {
		for(Bar bar : barList){
			scripManager.merge(bar.getScrip());
		}
		barDao.persistAll(barList);
	}
	
	@Override
	public List<Bar> getBarListByScripCode(String scripCode){
		return barDao.getBarListByScripCode(scripCode);
	}
	
	@Override
	public List<Bar> getBarListByScripCode(String scripCode, int count) {
		return barDao.getBarListByScripCode(scripCode, count);
	}

	@Override
	public Date getLastDownloadDate() {
		return barDao.getLastDownloadDate();
	}
}
